#include "stdafx.h"
#include "SPEA.h"
#include "Topology.h"

SPEA::SPEA(Topology* pTopology, As* pVictim, As* pAttacker) : 
	Attack(CreateSpeaMsg(pVictim, pAttacker),
	CreateWhoToSendToWithoutChangingLinks(pVictim, pAttacker))
{
}


SPEA::~SPEA()
{
}


Set<As*>* SPEA::CreateWhoToSendTo(Topology* pTopology)
{
	return pTopology->GetAss();
}

Set<As*>* SPEA::CreateWhoToSendToWithoutChangingLinks(As* pVictim, As* pAttacker)
{
	// return all neighbors except the first hop
	Set<Vertex*>* neighbors = new Set<Vertex*>();
	pAttacker->GetNeighbors(neighbors);
	Set<As*>* result = reinterpret_cast<Set<As*>*>(neighbors);
	return result;
}


BgpMessage* SPEA::CreateSpeaMsg(As* pVictim, As* pAttacker)
{
	Map<As*, Vector<As*> >* pathToVictim = new Map<As*, Vector<As*> > ();

	Vector<As*>* selfPath = new Vector<As*>();
	selfPath->push_back(pVictim);
	(*pathToVictim)[pVictim] = (*selfPath);

	BgpMessage* msg = new BgpMessage(pathToVictim);
	return msg;
}

